<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象方法</title>
</head>
<body>
    
</body>
</html>
<script>
    //格式化输出日期
    let time = new Date();
    // document.write(time*1);
    // console.log(Number(time))
    console.log(`
        ${time.getFullYear()}-${time.getMonth()}-${time.getDate()}  ${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}
    `);



    //封装函数用于复用
    function dateFormat(date,format="YYYY-MM-DD HH:mm:ss"){
        const config = {
            YYYY : date.getFullYear(),
            MM : date.getMonth()+1,
            DD : date.getDate(),
            HH : date.getHours(),
            mm : date.getMinutes(),
            ss : date.getSeconds()
        };
        for(const key in config){
            format = format.replace(key,config[key]);
        }
        return format;
    }
    console.log( dateFormat(new Date(),"YYYY年MM月DD日"));
</script>